
/**多边形配置项 */
interface PolygonOpt {
     map: AMap.Map,
     /**点集合 */
     path: AMap.LngLat[] | AMap.LngLat[][] | AMap.LngLat[][][] | undefined,
     /**线颜色 */
     strokeColor: string,
     /**线透明度 */
     strokeOpacity: number,
     /**线宽 */
     strokeWeight: number,
     /**填充色 */
     fillColor: string,
     /** 填充透明度*/
     fillOpacity: number,
     /** 层级*/
     zIndex: number,
     /**自定义数据 */
     extData: any
}
/**添加多边形 */
export const addPolygon = (opt: PolygonOpt): AMap.Polygon => {
     let polygon = new AMap.Polygon();
     polygon.setOptions({
          path: opt.path, //设置多边形边界路径
          strokeColor: opt.strokeColor, //线颜色
          strokeOpacity: opt.strokeOpacity, //线透明度
          strokeWeight: opt.strokeWeight, //线宽
          fillColor: opt.fillColor, //填充色
          fillOpacity: opt.fillOpacity, //填充透明度
          zIndex: opt.zIndex,
          extData: opt.extData
     })
     opt.map.add(polygon)

     return polygon
}
/**添加基地范围 */
export const addBaseRange = (
     map: AMap.Map,
     path: AMap.LngLat[] | AMap.LngLat[][] | AMap.LngLat[][][] | undefined,
     extData: any) => {
     return addPolygon({
          map: map,
          path: path,
          strokeColor: '#EB5B5B', //线颜色
          strokeOpacity: 0.9, //线透明度
          strokeWeight: 1, //线宽
          fillColor: '#FA5151', //填充色
          fillOpacity: 0.5, //填充透明度
          zIndex: 1,
          extData
     })
}
/**添加地块范围 */
export const addLandRange = (
     map: AMap.Map,
     path: AMap.LngLat[] | AMap.LngLat[][] | AMap.LngLat[][][] | undefined,
     extData: any) => {
     return addPolygon({
          map: map,
          path: path,
          strokeColor: '#1791fc', //线颜色
          strokeOpacity: 0.9, //线透明度
          strokeWeight: 1, //线宽
          fillColor: '#1791fc', //填充色
          fillOpacity: 0.5, //填充透明度
          zIndex: 10,
          extData
     })
}

/**点标记配置项 */
interface MarkerOpt {
     map: AMap.Map,
     lng: number,
     lat: number,
     text: string,
     imgUrl?: string,
     width?: number,
     height?: number,
     extData: any
}
/**添加点标记 */
export const addMarkerAndText = ({ map, lng, lat, text, imgUrl, width, height, extData }: MarkerOpt): AMap.Marker => {
     let _url = "//a.amap.com/jsapi_demos/static/demo-center/icons/poi-marker-default.png"
     let _width = 25
     let _height = 34
     if (imgUrl) {
          _url = imgUrl
     }
     if (width) {
          _width = width
     }
     if (height) {
          _height = height
     }

     let icon = new AMap.Icon({
          size: new AMap.Size(_width, _height), // 图标尺寸
          image: _url,
          imageSize: new AMap.Size(_width, _height),
     });


     let marker = new AMap.Marker({
          icon: icon,
          position: [lng, lat],
          anchor: 'bottom-center',
          extData,
          map
     });

     new AMap.Text({
          text: text,
          anchor: 'center', // 设置文本标记锚点
          angle: 0,
          offset: new AMap.Pixel(0, -90),
          style: {
               'text-align': 'center', 'box-shadow': '0 0 5px 0 rgba(0, 0, 0, 0.5)', padding: '5px 10px'
          },
          position: [lng, lat],
          map
     });

     return marker
}